<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script language="javascript" src="js/jquery-1.7.1.min.js"></script>
		<script>
			function formData(obj){
				return {
					version:"2.0",
					head:{"bodytype":"flat"},
					body:[obj]
				};
			};
			$(document).ready(function(){
				var base="";
				
				$("#btnAdd").click(function(){
					var data={
							code:$("input[name='code']").val(),
							password:$("input[name='password']").val(),
							sports:$("input[name='sports']").val(),
							clothes:$("input[name='clothes']").val(),
							gender:$("input[name='gender']").val(),
							age:$("input[name='age']").val(),
							income:$("input[name='income']").val()
						};
					var _id=$("input[name='_id']").val();
					if(_id!="")
						data["@id"]=_id;
					var req=JSON.stringify(formData(data));
					$("#formdata").val(req);
					$.post(base+"/user",req,function(data){
						$("#resultdata").val(JSON.stringify(data));
					});
				});
				
				$("#btnAddRest").click(function(){
					var req=JSON.stringify(formData({
						code:$("input[name='code']").val(),
						password:$("input[name='password']").val(),
						sports:$("input[name='sports']").val(),
						clothes:$("input[name='clothes']").val(),
						age:$("input[name='age']").val(),
						gender:$("input[name='gender']").val(),
						income:$("input[name='income']").val()
					}));
					$("#formdata").val(req);
					$.post(base+"/ruser",req,function(data){
						$("#resultdata").val(JSON.stringify(data));
					});
				});
				
				$("#btnGet").click(function(){
					var path=base+"/user/"+$("input[name='code']").val();
					$("#formdata").val(path);
					$.get(path,function(data){
						$("#resultdata").val(JSON.stringify(data));
					});
				});
				
				$("#btnGetRest").click(function(){
					var path=base+"/ruser/"+$("input[name='code']").val();
					$("#formdata").val(path);
					$.get(path,function(data){
						$("#resultdata").val(JSON.stringify(data));
					});
				});
				
				$("#btnList").click(function(){
					var path=base+"/user/list";
					$("#formdata").val(path);
					$.get(path,function(data){
						$("#resultdata").val(JSON.stringify(data));
					});
				});
				
				$("#btnListRest").click(function(){
					var path=base+"/ruser/list";
					$("#formdata").val(path);
					$.get(path,function(data){
						$("#resultdata").val(JSON.stringify(data));
					});
				});
				
			});
		</script>
	</head>
	<body>
		<h1>Example</h1>
		<form id="form1" action="user.xft" >
		<table border="0">
			<tr><td valign="bottom">
				<table border="0">
					<tr><td align="right">编码:</td><td><input name="code" /></td></tr>
					<tr><td align="right">密码:</td><td><input name="password" /></td></tr>
					<tr><td align="right">性别:</td><td><input name="gender" /></td></tr>
					<tr><td align="right">体育:</td><td><input name="sports" /></td></tr>
					<tr><td align="right">衣服:</td><td><input name="clothes" /></td></tr>
					<tr><td align="right">年龄:</td><td><input name="age" /></td></tr>
					<tr><td align="right">收入:</td><td><input name="income" /></td></tr>
					<tr><td align="right">表单id:</td><td><input name="_id" /></td></tr>
				</table>
			</td>
			<td>
	<pre>
	@Form
	public class User {
		@Field(label="编码",required="1",facets=@Facets(minLength=3,maxLength=8))
		private String code;
		@Field(label="性别",required="1",facets=@Facets(enums="男,女"))
		private String gender;
		@Field(label="密码",required="1")
		private String password;
		@Field(label="体育",required="gender=='男'",facets=@Facets(enums="足球,篮球"))
		private String sports;
		@Field(label="衣服",required="gender=='女'",facets=@Facets(maxLength=20))
		private String clothes;
		@Field(label="年龄")
		private Integer age;
		@Field(label="收入",required="notnull(age)",checks= {@Check(exp="value()&gt;age*3 && value()&lt;age*5",text="收入必须在年龄的3倍与5倍之间")})
		private Integer income;
		...
	}
	</pre>
			</td>
		</tr></table>
		</form>
		<button id="btnAdd">添加</button><button id="btnGet">加载</button><button id="btnList">列表</button></br>
		<button id="btnAddRest">Rest添加</button><button id="btnGetRest">Rest加载</button><button id="btnListRest">Rest列表</button></br>
		请求数据:<br/>
		<textarea id="formdata" cols="80" rows="5">
		
		</textarea><br/>
		请求结果:<br/>
		<textarea id="resultdata" cols="80" rows="5">
		
		</textarea><br/>
	</body>
</html>
